1 Imports System.Data.SqlClient
2 Imports System.IO
3
4 Public Class frmStudent
5     Dim s1 As String
6     Dim Photoname As String =
""
7     Dim IsImageChanged As Boolean = False
8     Sub Reset()
9         txtAdmissionNo.Text =
""
10         txtEnrollmentNo.Text =
""
11         txtClass.Text =
""
12         txtContactNo.Text =
""
13         txtDocID.Text =
""
14         txtGRNo.Text =
""
15         txtUID.Text =
""
16         txtLastSchoolAttended.Text =
""
17         cmbResult.SelectedIndex = -
1
18         txtPercentage.Text =
""
19         txtEmailID.Text =
""
20         txtEnrollmentNo.Text =
""
21         txtFatherContactNo.Text =
""
22         txtFathername.Text =
""
23         txtMotherName.Text =
""
24         txtNationality.Text =
""
25         txtPermanentAddress.Text =
""
26         txtSection.Text =
""
27         cmbSession.SelectedIndex = -
1
28         txtStudentName.Text =
""
29         txtTemrorayAddress.Text =
""
30         cmbSchoolName.SelectedIndex = -
1
31         cmbCategory.SelectedIndex = -
1
32         cmbDocumentsSubmitted.SelectedIndex = -
1
33         cmbReligion.SelectedIndex = -
1
34         cmbStatus.SelectedIndex = -
1
35         dtpAdmissionDate.Text = Today
36         dtpDOB.Text = Today
37         ListView1.Items.Clear()
38         rbFemale.Checked = False
39         rbMale.Checked = False
40         btnDelete.Enabled = False
41         btnUpdate.Enabled = False
42         btnSave.Enabled = True
43         txtPercentage.ReadOnly = True
44         Picture.Image = My.Resources.photo
45     End Sub
46
47
48     Private Sub Browse_Click_1(sender As System.Object, e As System.EventArgs) Handles Browse.Click
49         Try
50             With OpenFileDialog1
51                 .Filter = (
"Images |*.png; *.bmp; *.jpg;*.jpeg; *.gif;")
52                 .FilterIndex =
4
53             End With
54             
'Clear the file name
55             OpenFileDialog1.FileName =
""
56             If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
57                 Picture.Image = Image.FromFile(OpenFileDialog1.FileName)
58             End If
59         Catch ex As Exception
60             MsgBox(ex.ToString())
61         End Try
62     End Sub
63
64     Private Sub BRemove_Click(sender As System.Object, e As System.EventArgs) Handles BRemove.Click
65         Picture.Image = My.Resources.photo
66     End Sub
67
68     Private Sub BStartCapture_Click(sender As System.Object, e As System.EventArgs) Handles BStartCapture.Click
69         Dim k As New frmCamera
70         k.ShowDialog()
71         If TempFileNames2.Length >
0 Then
72
73             Picture.Image = Image.FromFile(TempFileNames2)
74             Photoname = TempFileNames2
75             IsImageChanged = True
76         End If
77     End Sub
78
79     Private Sub btnNew_Click(sender As System.Object, e As System.EventArgs) Handles btnNew.Click
80         Reset()
81     End Sub
82
83     Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
84         Try
85             If Len(Trim(cmbSchoolName.Text)) =
0 Then
86                 MessageBox.Show(
"Please select school name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
87                 cmbSchoolName.Focus()
88                 Exit Sub
89             End If
90             If Len(Trim(txtAdmissionNo.Text)) =
0 Then
91                 MessageBox.Show(
"Please enter admission no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
92                 txtAdmissionNo.Focus()
93                 Exit Sub
94             End If
95             If Len(Trim(txtGRNo.Text)) =
0 Then
96                 MessageBox.Show(
"Please enter GR no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
97                 txtGRNo.Focus()
98                 Exit Sub
99             End If
100             If Len(Trim(txtStudentName.Text)) =
0 Then
101                 MessageBox.Show(
"Please enter student name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
102                 txtStudentName.Focus()
103                 Exit Sub
104             End If
105             If rbMale.Checked = False And rbFemale.Checked = False Then
106                 MessageBox.Show(
"Please check gender", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
107                 Exit Sub
108             End If
109             If Len(Trim(cmbSession.Text)) =
0 Then
110                 MessageBox.Show(
"Please select session", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
111                 cmbSession.Focus()
112                 Exit Sub
113             End If
114             If Len(Trim(cmbReligion.Text)) =
0 Then
115                 MessageBox.Show(
"Please select religion", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
116                 cmbReligion.Focus()
117                 Exit Sub
118             End If
119             If Len(Trim(cmbCategory.Text)) =
0 Then
120                 MessageBox.Show(
"Please select category", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
121                 cmbCategory.Focus()
122                 Exit Sub
123             End If
124             If Len(Trim(txtFathername.Text)) =
0 Then
125                 MessageBox.Show(
"Please enter father's name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
126                 txtFathername.Focus()
127                 Exit Sub
128             End If
129             If Len(Trim(txtMotherName.Text)) =
0 Then
130                 MessageBox.Show(
"Please enter mother's name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
131                 txtMotherName.Focus()
132                 Exit Sub
133             End If
134             If ListView1.Items.Count =
0 Then
135                 MessageBox.Show(
"Please add documents submitted to listview", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
136                 cmbDocumentsSubmitted.Focus()
137                 Exit Sub
138             End If
139             If Len(Trim(txtTemrorayAddress.Text)) =
0 Then
140                 MessageBox.Show(
"Please enter temporary address", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
141                 txtTemrorayAddress.Focus()
142                 Exit Sub
143             End If
144             If Len(Trim(txtPermanentAddress.Text)) =
0 Then
145                 MessageBox.Show(
"Please enter permanent address", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
146                 txtPermanentAddress.Focus()
147                 Exit Sub
148             End If
149             If Len(Trim(txtContactNo.Text)) =
0 Then
150                 MessageBox.Show(
"Please enter contact no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
151                 txtContactNo.Focus()
152                 Exit Sub
153             End If
154             If Len(Trim(txtClass.Text)) =
0 Then
155                 MessageBox.Show(
"Please retrieve class", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
156                 txtClass.Focus()
157                 Exit Sub
158             End If
159             If Len(Trim(txtSection.Text)) =
0 Then
160                 MessageBox.Show(
"Please retrieve section", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
161                 txtSection.Focus()
162                 Exit Sub
163             End If
164             If Len(Trim(cmbStatus.Text)) =
0 Then
165                 MessageBox.Show(
"Please select status", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
166                 cmbStatus.Focus()
167                 Exit Sub
168             End If
169             con = New SqlConnection(cs)
170             con.Open()
171             Dim ct As String =
"select AdmissionNo from Student where AdmissionNo=@d1"
172             cmd = New SqlCommand(ct)
173             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
174             cmd.Connection = con
175             rdr = cmd.ExecuteReader()
176
177             If rdr.Read() Then
178                 MessageBox.Show(
"Admission No. Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
179                 txtAdmissionNo.Text =
""
180                 txtAdmissionNo.Focus()
181                 If (rdr IsNot Nothing) Then
182                     rdr.Close()
183                 End If
184                 Return
185             End If
186             If rbMale.Checked = True Then
187                 s1 = rbMale.Text
188             End If
189             If rbFemale.Checked = True Then
190                 s1 = rbFemale.Text
191             End If
192             con = New SqlConnection(cs)
193             con.Open()
194             Dim cb As String =
"insert into Student(AdmissionNo, EnrollmentNo, GRNo, UID, StudentName, FatherName, MotherName, FatherCN, PermanentAddress, TemporaryAddress, ContactNo, EmailID, DOB, Gender, AdmissionDate, Session, Caste, Religion,SectionID, Nationality, SchoolID, LastSchoolAttended, Result, PassPercentage, Status,Photo) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16,@d17,@d18,@d19,@d20,@d21,@d22,@d23,@d24,@d25,@d26)"
195             cmd = New SqlCommand(cb)
196             cmd.Connection = con
197             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
198             cmd.Parameters.AddWithValue(
"@d2", txtEnrollmentNo.Text)
199             cmd.Parameters.AddWithValue(
"@d3", txtGRNo.Text)
200             cmd.Parameters.AddWithValue(
"@d4", txtUID.Text)
201             cmd.Parameters.AddWithValue(
"@d5", txtStudentName.Text)
202             cmd.Parameters.AddWithValue(
"@d6", txtFathername.Text)
203             cmd.Parameters.AddWithValue(
"@d7", txtMotherName.Text)
204             cmd.Parameters.AddWithValue(
"@d8", txtFatherContactNo.Text)
205             cmd.Parameters.AddWithValue(
"@d9", txtPermanentAddress.Text)
206             cmd.Parameters.AddWithValue(
"@d10", txtTemrorayAddress.Text)
207             cmd.Parameters.AddWithValue(
"@d11", txtContactNo.Text)
208             cmd.Parameters.AddWithValue(
"@d12", txtEmailID.Text)
209             cmd.Parameters.AddWithValue(
"@d13", dtpDOB.Text)
210             cmd.Parameters.AddWithValue(
"@d14", s1)
211             cmd.Parameters.AddWithValue(
"@d15", dtpAdmissionDate.Text)
212             cmd.Parameters.AddWithValue(
"@d16", cmbSession.Text)
213             cmd.Parameters.AddWithValue(
"@d17", cmbCategory.Text)
214             cmd.Parameters.AddWithValue(
"@d18", cmbReligion.Text)
215             cmd.Parameters.AddWithValue(
"@d19", txtSectionID.Text)
216             cmd.Parameters.AddWithValue(
"@d20", txtNationality.Text)
217             cmd.Parameters.AddWithValue(
"@d21", txtSchoolID.Text)
218             cmd.Parameters.AddWithValue(
"@d22", txtLastSchoolAttended.Text)
219             cmd.Parameters.AddWithValue(
"@d23", cmbResult.Text)
220             cmd.Parameters.AddWithValue(
"@d24", txtPercentage.Text)
221             cmd.Parameters.AddWithValue(
"@d25", cmbStatus.Text)
222             Dim ms As New MemoryStream()
223             Dim bmpImage As New Bitmap(Picture.Image)
224             bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
225             Dim data As Byte() = ms.GetBuffer()
226             Dim p As New SqlParameter(
"@d26", SqlDbType.Image)
227             p.Value = data
228             cmd.Parameters.Add(p)
229             cmd.ExecuteNonQuery()
230             For i =
0 To ListView1.Items.Count - 1
231                 con = New SqlConnection(cs)
232                 Dim cd As String =
"insert Into StudentDocSubmitted(AdmissionNo,DocID) VALUES (@d1,@d2)"
233                 cmd = New SqlCommand(cd)
234                 cmd.Connection = con
235                 cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
236                 cmd.Parameters.AddWithValue(
"@d2", CInt(ListView1.Items(i).SubItems(1).Text))
237                 con.Open()
238                 cmd.ExecuteNonQuery()
239                 con.Close()
240             Next
241             con = New SqlConnection(cs)
242             con.Open()
243             Dim cb1 As String =
"insert into Cards_Student(AdmissionNo) VALUES (@d1)"
244             cmd = New SqlCommand(cb1)
245             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
246             cmd.Connection = con
247             cmd.ExecuteReader()
248             con.Close()
249             con = New SqlConnection(cs)
250             con.Open()
251             Dim cb2 As String =
"insert into NoDues_Student(AdmissionNo) VALUES (@d1)"
252             cmd = New SqlCommand(cb2)
253             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
254             cmd.Connection = con
255             cmd.ExecuteReader()
256             con.Close()
257             con = New SqlConnection(cs)
258             con.Open()
259             Dim cb3 As String =
"insert into Discount(AdmissionNo,FeeType,Discount) VALUES (@d1,'Class',0.00)"
260             cmd = New SqlCommand(cb3)
261             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
262             cmd.Connection = con
263             cmd.ExecuteReader()
264             con.Close()
265             con = New SqlConnection(cs)
266             con.Open()
267             Dim cb4 As String =
"insert into Discount(AdmissionNo,FeeType,Discount) VALUES (@d1,'Hostel',0.00)"
268             cmd = New SqlCommand(cb4)
269             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
270             cmd.Connection = con
271             cmd.ExecuteReader()
272             con.Close()
273             con = New SqlConnection(cs)
274             con.Open()
275             Dim cb5 As String =
"insert into Discount(AdmissionNo,FeeType,Discount) VALUES (@d1,'Bus',0.00)"
276             cmd = New SqlCommand(cb5)
277             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
278             cmd.Connection = con
279             cmd.ExecuteReader()
280             con.Close()
281             LogFunc(lblUser.Text,
"added new student '" & txtStudentName.Text & "' has admission no. '" & txtAdmissionNo.Text & "'")
282             MessageBox.Show(
"Successfully saved", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
283             btnSave.Enabled = False
284
285             If con.State = ConnectionState.Open Then
286                 con.Close()
287             End If
288             con.Close()
289
290         Catch ex As Exception
291             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
292         End Try
293     End Sub
294
295     Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
296         Try
297             If MessageBox.Show(
"Do you really want to delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
298                 DeleteRecord()
299             End If
300         Catch ex As Exception
301             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
302         End Try
303     End Sub
304     Public Sub DeleteRecord()
305         Try
306             Dim RowsAffected As Integer =
0
307             con = New SqlConnection(cs)
308             con.Open()
309             Dim cl As String =
"select Student.AdmissionNo from Student,Hosteler where Student.AdmissionNo=Hosteler.AdmissionNo and Student.AdmissionNo=@d1"
310             cmd = New SqlCommand(cl)
311             cmd.Connection = con
312             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
313             rdr = cmd.ExecuteReader()
314             If rdr.Read Then
315                 MessageBox.Show(
"Unable to delete..Already in use in Hosteler Entry", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
316                 If Not rdr Is Nothing Then
317                     rdr.Close()
318                 End If
319                 Exit Sub
320             End If
321             con = New SqlConnection(cs)
322             con.Open()
323             Dim cl2 As String =
"select Student.AdmissionNo from Student,BusCardHolder_Student where Student.AdmissionNo=BusCardHolder_Student.AdmissionNo and Student.AdmissionNo=@d1"
324             cmd = New SqlCommand(cl2)
325             cmd.Connection = con
326             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
327             rdr = cmd.ExecuteReader()
328             If rdr.Read Then
329                 MessageBox.Show(
"Unable to delete..Already in use in Bus Card Holder[Student] Entry", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
330                 If Not rdr Is Nothing Then
331                     rdr.Close()
332                 End If
333                 Exit Sub
334             End If
335             con = New SqlConnection(cs)
336             con.Open()
337             Dim cl1 As String =
"select Student.AdmissionNo from Student,CourseFeePayment where Student.AdmissionNo=CourseFeePayment.AdmissionNo and Student.AdmissionNo=@d1"
338             cmd = New SqlCommand(cl1)
339             cmd.Connection = con
340             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
341             rdr = cmd.ExecuteReader()
342             If rdr.Read Then
343                 MessageBox.Show(
"Unable to delete..Already in use in Course Fee Payment Entry", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
344                 If Not rdr Is Nothing Then
345                     rdr.Close()
346                 End If
347                 Exit Sub
348             End If
349             con = New SqlConnection(cs)
350             con.Open()
351             Dim cq As String =
"delete from Student where AdmissionNo=@d1"
352             cmd = New SqlCommand(cq)
353             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
354             cmd.Connection = con
355             RowsAffected = cmd.ExecuteNonQuery()
356             If RowsAffected >
0 Then
357                 LogFunc(lblUser.Text,
"deleted the student '" & txtStudentName.Text & "' has admission no. '" & txtAdmissionNo.Text & "'")
358                 MessageBox.Show(
"Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
359                 Reset()
360             Else
361                 MessageBox.Show(
"No record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information)
362                 Reset()
363             End If
364             con.Close()
365         Catch ex As Exception
366             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
367         End Try
368     End Sub
369
370     Private Sub btnUpdate_Click(sender As System.Object, e As System.EventArgs) Handles btnUpdate.Click
371         Try
372             If Len(Trim(cmbSchoolName.Text)) =
0 Then
373                 MessageBox.Show(
"Please select school name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
374                 cmbSchoolName.Focus()
375                 Exit Sub
376             End If
377             If Len(Trim(txtAdmissionNo.Text)) =
0 Then
378                 MessageBox.Show(
"Please enter admission no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
379                 txtAdmissionNo.Focus()
380                 Exit Sub
381             End If
382             If Len(Trim(txtGRNo.Text)) =
0 Then
383                 MessageBox.Show(
"Please enter GR no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
384                 txtGRNo.Focus()
385                 Exit Sub
386             End If
387             If Len(Trim(txtStudentName.Text)) =
0 Then
388                 MessageBox.Show(
"Please enter student name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
389                 txtStudentName.Focus()
390                 Exit Sub
391             End If
392             If Len(Trim(cmbSession.Text)) =
0 Then
393                 MessageBox.Show(
"Please select session", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
394                 cmbSession.Focus()
395                 Exit Sub
396             End If
397             If rbMale.Checked = False And rbFemale.Checked = False Then
398                 MessageBox.Show(
"Please check gender", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
399                 Exit Sub
400             End If
401             If Len(Trim(cmbReligion.Text)) =
0 Then
402                 MessageBox.Show(
"Please select religion", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
403                 cmbReligion.Focus()
404                 Exit Sub
405             End If
406             If Len(Trim(cmbCategory.Text)) =
0 Then
407                 MessageBox.Show(
"Please select category", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
408                 cmbCategory.Focus()
409                 Exit Sub
410             End If
411             If Len(Trim(txtFathername.Text)) =
0 Then
412                 MessageBox.Show(
"Please enter father's name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
413                 txtFathername.Focus()
414                 Exit Sub
415             End If
416             If Len(Trim(txtMotherName.Text)) =
0 Then
417                 MessageBox.Show(
"Please enter mother's name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
418                 txtMotherName.Focus()
419                 Exit Sub
420             End If
421             If ListView1.Items.Count =
0 Then
422                 MessageBox.Show(
"Please add documents submitted to listview", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
423                 cmbDocumentsSubmitted.Focus()
424                 Exit Sub
425             End If
426             If Len(Trim(txtTemrorayAddress.Text)) =
0 Then
427                 MessageBox.Show(
"Please enter temporary address", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
428                 txtTemrorayAddress.Focus()
429                 Exit Sub
430             End If
431             If Len(Trim(txtPermanentAddress.Text)) =
0 Then
432                 MessageBox.Show(
"Please enter permanent address", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
433                 txtPermanentAddress.Focus()
434                 Exit Sub
435             End If
436             If Len(Trim(txtContactNo.Text)) =
0 Then
437                 MessageBox.Show(
"Please enter contact no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
438                 txtContactNo.Focus()
439                 Exit Sub
440             End If
441             If Len(Trim(txtClass.Text)) =
0 Then
442                 MessageBox.Show(
"Please retrieve class", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
443                 txtClass.Focus()
444                 Exit Sub
445             End If
446             If Len(Trim(txtSection.Text)) =
0 Then
447                 MessageBox.Show(
"Please retrieve section", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
448                 txtSection.Focus()
449                 Exit Sub
450             End If
451             If Len(Trim(cmbStatus.Text)) =
0 Then
452                 MessageBox.Show(
"Please select status", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
453                 cmbStatus.Focus()
454                 Exit Sub
455             End If
456
457             If rbMale.Checked = True Then
458                 s1 = rbMale.Text
459             End If
460             If rbFemale.Checked = True Then
461                 s1 = rbFemale.Text
462             End If
463             con = New SqlConnection(cs)
464             con.Open()
465             Dim cb As String =
"Update Student set EnrollmentNo=@d2, GRNo=@d3, UID=@d4, StudentName=@d5, FatherName=@d6, MotherName=@d7, FatherCN=@d8, PermanentAddress=@d9, TemporaryAddress=@d10, ContactNo=@d11, EmailID=@d12, DOB=@d13, Gender=@d14, AdmissionDate=@d15, Session=@d16, Caste=@d17, Religion=@d18,SectionID=@d19, Nationality=@d20, SchoolID=@d21, LastSchoolAttended=@d22, Result=@d23, PassPercentage=@d24, Status=@d25,Photo=@d26,AdmissionNo=@d27 where AdmissionNo=@d1"
466             cmd = New SqlCommand(cb)
467             cmd.Connection = con
468
469             cmd.Parameters.AddWithValue(
"@d2", txtEnrollmentNo.Text)
470             cmd.Parameters.AddWithValue(
"@d3", txtGRNo.Text)
471             cmd.Parameters.AddWithValue(
"@d4", txtUID.Text)
472             cmd.Parameters.AddWithValue(
"@d5", txtStudentName.Text)
473             cmd.Parameters.AddWithValue(
"@d6", txtFathername.Text)
474             cmd.Parameters.AddWithValue(
"@d7", txtMotherName.Text)
475             cmd.Parameters.AddWithValue(
"@d8", txtFatherContactNo.Text)
476             cmd.Parameters.AddWithValue(
"@d9", txtPermanentAddress.Text)
477             cmd.Parameters.AddWithValue(
"@d10", txtTemrorayAddress.Text)
478             cmd.Parameters.AddWithValue(
"@d11", txtContactNo.Text)
479             cmd.Parameters.AddWithValue(
"@d12", txtEmailID.Text)
480             cmd.Parameters.AddWithValue(
"@d13", dtpDOB.Text)
481             cmd.Parameters.AddWithValue(
"@d14", s1)
482             cmd.Parameters.AddWithValue(
"@d15", dtpAdmissionDate.Text)
483             cmd.Parameters.AddWithValue(
"@d16", cmbSession.Text)
484             cmd.Parameters.AddWithValue(
"@d17", cmbCategory.Text)
485             cmd.Parameters.AddWithValue(
"@d18", cmbReligion.Text)
486             cmd.Parameters.AddWithValue(
"@d19", txtSectionID.Text)
487             cmd.Parameters.AddWithValue(
"@d20", txtNationality.Text)
488             cmd.Parameters.AddWithValue(
"@d21", txtSchoolID.Text)
489             cmd.Parameters.AddWithValue(
"@d22", txtLastSchoolAttended.Text)
490             cmd.Parameters.AddWithValue(
"@d23", cmbResult.Text)
491             cmd.Parameters.AddWithValue(
"@d24", txtPercentage.Text)
492             cmd.Parameters.AddWithValue(
"@d25", cmbStatus.Text)
493             Dim ms As New MemoryStream()
494             Dim bmpImage As New Bitmap(Picture.Image)
495             bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
496             Dim data As Byte() = ms.GetBuffer()
497             Dim p As New SqlParameter(
"@d26", SqlDbType.Image)
498             p.Value = data
499             cmd.Parameters.Add(p)
500             cmd.Parameters.AddWithValue(
"@d27", txtAdmissionNo1.Text)
501             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
502             cmd.ExecuteNonQuery()
503             con.Close()
504             con = New SqlConnection(cs)
505             con.Open()
506             Dim cq As String =
"delete from StudentDocSubmitted where AdmissionNo=@d1"
507             cmd = New SqlCommand(cq)
508             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
509             cmd.Connection = con
510             cmd.ExecuteNonQuery()
511             con.Close()
512             For i =
0 To ListView1.Items.Count - 1
513                 con = New SqlConnection(cs)
514                 Dim cd As String =
"insert Into StudentDocSubmitted(AdmissionNo,DocID) VALUES (@d1,@d2)"
515                 cmd = New SqlCommand(cd)
516                 cmd.Connection = con
517                 cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
518                 cmd.Parameters.AddWithValue(
"@d2", CInt(ListView1.Items(i).SubItems(1).Text))
519                 con.Open()
520                 cmd.ExecuteNonQuery()
521                 con.Close()
522             Next
523        
524             LogFunc(lblUser.Text,
"updated student '" & txtStudentName.Text & "' has admission no. '" & txtAdmissionNo.Text & "'")
525             MessageBox.Show(
"Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
526             btnUpdate.Enabled = False
527
528             If con.State = ConnectionState.Open Then
529                 con.Close()
530             End If
531             con.Close()
532
533         Catch ex As Exception
534             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
535         End Try
536     End Sub
537
538     Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
539         Try
540             If Len(Trim(cmbDocumentsSubmitted.Text)) =
0 Then
541                 MessageBox.Show(
"Please select doc submitted", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
542                 cmbDocumentsSubmitted.Focus()
543                 Exit Sub
544             End If
545             Dim temp As Integer
546             temp = ListView1.Items.Count()
547             If temp =
0 Then
548                 Dim i As Integer
549                 Dim lst As New ListViewItem(i)
550                 lst.SubItems.Add(txtDocID.Text)
551                 lst.SubItems.Add(cmbDocumentsSubmitted.Text)
552                 ListView1.Items.Add(lst)
553                 i = i +
1
554                 cmbDocumentsSubmitted.SelectedIndex = -
1
555                 Exit Sub
556             End If
557             For j =
0 To temp - 1
558                 If (ListView1.Items(j).SubItems(
2).Text = cmbDocumentsSubmitted.Text) Then
559                     MessageBox.Show(
"Doc already added", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
560                     Exit Sub
561                 End If
562             Next j
563             Dim k As Integer
564             Dim lst1 As New ListViewItem(k)
565             lst1.SubItems.Add(txtDocID.Text)
566             lst1.SubItems.Add(cmbDocumentsSubmitted.Text)
567             ListView1.Items.Add(lst1)
568             k = k +
1
569             cmbDocumentsSubmitted.SelectedIndex = -
1
570         Catch ex As Exception
571             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
572         End Try
573     End Sub
574
575     Private Sub btnRemove_Click(sender As System.Object, e As System.EventArgs) Handles btnRemove.Click
576         Try
577             If (ListView1.SelectedItems.Count >
0) Then
578                 Dim itmCnt, i, t As Integer
579                 ListView1.FocusedItem.Remove()
580                 itmCnt = ListView1.Items.Count
581                 t =
1
582                 For i =
1 To itmCnt + 1
583
584                     
'Dim lst1 As New ListViewItem(i)
585                     
'ListView1.Items(i).SubItems(0).Text = t
586                     t = t +
1
587                 Next
588                 btnRemove.Enabled = False
589             End If
590         Catch ex As Exception
591             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
592         End Try
593     End Sub
594
595     Private Sub ListView1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListView1.SelectedIndexChanged
596         btnRemove.Enabled = True
597     End Sub
598
599     Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
600         frmSectionRecord.Reset()
601         frmSectionRecord.lblSet.Text =
"Student Entry"
602         frmSectionRecord.ShowDialog()
603     End Sub
604
605     Private Sub cmbResult_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbResult.SelectedIndexChanged
606         If cmbResult.Text =
"Pass" Then
607             txtPercentage.ReadOnly = False
608         End If
609         If cmbResult.Text =
"Fail" Then
610             txtPercentage.ReadOnly = True
611         End If
612     End Sub
613
614     Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
615         Me.Close()
616     End Sub
617
618     Private Sub cmbSchoolName_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbSchoolName.SelectedIndexChanged
619         Try
620             con = New SqlConnection(cs)
621             con.Open()
622             cmd = con.CreateCommand()
623             cmd.CommandText =
"SELECT S_ID FROM SchoolInfo where SchoolName=@d1"
624             cmd.Parameters.AddWithValue(
"@d1", cmbSchoolName.Text)
625             rdr = cmd.ExecuteReader()
626             If rdr.Read() Then
627                 txtSchoolID.Text = rdr.GetValue(
0)
628             End If
629             If (rdr IsNot Nothing) Then
630                 rdr.Close()
631             End If
632             If con.State = ConnectionState.Open Then
633                 con.Close()
634             End If
635         Catch ex As Exception
636             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
637         End Try
638     End Sub
639     Sub fillSchool()
640         Try
641             con = New SqlConnection(cs)
642             con.Open()
643             adp = New SqlDataAdapter()
644             adp.SelectCommand = New SqlCommand(
"SELECT distinct (SchoolName) FROM SchoolInfo", con)
645             ds = New DataSet(
"ds")
646             adp.Fill(ds)
647             dtable = ds.Tables(
0)
648             cmbSchoolName.Items.Clear()
649             For Each drow As DataRow In dtable.Rows
650                 cmbSchoolName.Items.Add(drow(
0).ToString())
651             Next
652         Catch ex As Exception
653             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
654         End Try
655     End Sub
656     Sub fillDocs()
657         Try
658             con = New SqlConnection(cs)
659             con.Open()
660             adp = New SqlDataAdapter()
661             adp.SelectCommand = New SqlCommand(
"SELECT distinct (DocName) FROM Document", con)
662             ds = New DataSet(
"ds")
663             adp.Fill(ds)
664             dtable = ds.Tables(
0)
665             cmbDocumentsSubmitted.Items.Clear()
666             For Each drow As DataRow In dtable.Rows
667                 cmbDocumentsSubmitted.Items.Add(drow(
0).ToString())
668             Next
669         Catch ex As Exception
670             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
671         End Try
672     End Sub
673     Sub fillSession()
674         Try
675             con = New SqlConnection(cs)
676             con.Open()
677             adp = New SqlDataAdapter()
678             adp.SelectCommand = New SqlCommand(
"SELECT distinct (Session) FROM Session_Master", con)
679             ds = New DataSet(
"ds")
680             adp.Fill(ds)
681             dtable = ds.Tables(
0)
682             cmbSession.Items.Clear()
683             For Each drow As DataRow In dtable.Rows
684                 cmbSession.Items.Add(drow(
0).ToString())
685             Next
686         Catch ex As Exception
687             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
688         End Try
689     End Sub
690     Private Sub frmStudent_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
691         fillSchool()
692         fillDocs()
693         fillSession()
694     End Sub
695
696     Private Sub cmbDocumentsSubmitted_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbDocumentsSubmitted.SelectedIndexChanged
697         Try
698             con = New SqlConnection(cs)
699             con.Open()
700             cmd = con.CreateCommand()
701             cmd.CommandText =
"SELECT Doc_ID FROM Document where DocName=@d1"
702             cmd.Parameters.AddWithValue(
"@d1", cmbDocumentsSubmitted.Text)
703             rdr = cmd.ExecuteReader()
704             If rdr.Read() Then
705                 txtDocID.Text = rdr.GetValue(
0)
706             End If
707             If (rdr IsNot Nothing) Then
708                 rdr.Close()
709             End If
710             If con.State = ConnectionState.Open Then
711                 con.Close()
712             End If
713         Catch ex As Exception
714             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
715         End Try
716     End Sub
717
718     Private Sub btnGetData_Click(sender As System.Object, e As System.EventArgs) Handles btnGetData.Click
719         frmStudentRecord.Reset()
720         frmStudentRecord.lblSet.Text =
"Student Entry"
721         frmStudentRecord.ShowDialog()
722     End Sub
723
724     Private Sub txtPercentage_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtPercentage.KeyPress
725         Dim keyChar = e.KeyChar
726
727         If Char.IsControl(keyChar) Then
728             
'Allow all control characters.
729         ElseIf Char.IsDigit(keyChar) OrElse keyChar =
"."c Then
730             Dim text = Me.txtPercentage.Text
731             Dim selectionStart = Me.txtPercentage.SelectionStart
732             Dim selectionLength = Me.txtPercentage.SelectionLength
733
734             text = text.Substring(
0, selectionStart) & keyChar & text.Substring(selectionStart + selectionLength)
735
736             If Integer.TryParse(text, New Integer) AndAlso text.Length >
16 Then
737                 
'Reject an integer that is longer than 16 digits.
738                 e.Handled = True
739             ElseIf Double.TryParse(text, New Double) AndAlso text.IndexOf(
"."c) < text.Length - 3 Then
740                 
'Reject a real number with two many decimal places.
741                 e.Handled = False
742             End If
743         Else
744             
'Reject all other characters.
745             e.Handled = True
746         End If
747     End Sub
748 End Class


Gõ tìm kiếm nhanh...